import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import tagsView from './modules/tagsView'
import user from './modules/user'
import siddhi from './modules/siddhi'
import projection from './modules/projection'
import inputSource from './modules/inputSource'
import permission from './modules/permission'
import application from './modules/application'
import tenantConfigCommand from './modules/tenantConfigCommand'
import autocomplete from './modules/autocomplete'
import centralizedControl from './modules/centralizedControl'
import baseData from './modules/baseData'
Vue.use(Vuex)
import createPersistedState from "vuex-persistedstate"
const store = new Vuex.Store({
  modules: {
    app,
    settings,
    tagsView,
    user,
    siddhi,
    projection,
    inputSource, permission,
    application,
    tenantConfigCommand,
    autocomplete,
    centralizedControl,
    baseData
  },
  getters,
  //配置vuex本地化存储 解决刷新问题 (主要使用在 用户模块- token和租户之类的数据)
  plugins: [createPersistedState({
    //指定需要持久化的state,配置如下
    storage: window.localStorage,
    reducer(val) {
      // console.log('val :>> ', val.user);
      return {
        // user: val.user //设置整个user模块持久化
        // 单独设置模块下的某一个参数持久化
        autocomplete: {
          autocompleteList: val.autocomplete.autocompleteList,
        },
        user: {
          authToken: val.user.authToken,//后续删除
          // jwt:val.authToken, //后续删除
          // user: getCookie('user'),
          user: val.user.user, //用户信息
          tenant: val.user.tenant,//当前选择的租户
          // routes: val.authToken,//拥有的路由
          tenantList: val.user.tenantList,//拥有的租户
          usernamePassword: val.user.usernamePassword,//账号密码存储--后续获取token使用
          accessToken: val.user.accessToken,//全局的jwt令牌
          authTokenInfo: val.user.authTokenInfo//jwt令牌对象-内部包含了刷新使用的token
        },
      }
    }
  })]
})
export default store
